package nyist.media.controller;

import nyist.media.page.ApiResult;
import nyist.media.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 操作日志
 * @author : dcf
 * @date : 2019/3/15
 */

@RestController
@RequestMapping(value = "/admin/logs", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public class LogsController extends BaseController {

    @Autowired
    private LogService logService;

    /**
     * 查看所有操作日志
     * @param keyword 搜索的关键字
     * @param page 页码
     * @param limit 页长
     * @return 操作日志列表
     */
    @GetMapping
    public Map<String, Object> logs(String keyword, Integer page, Integer limit) {
        PageRequest pageRequest = new PageRequest(page - 1, limit);
        return toResultPage(logService.findLogs(pageRequest, keyword));

    }

    /**
     * 晴空操作日志
     * @return 状态码 20000 状态信息：响应成功
     */
    @DeleteMapping("/all")
    public Map<String, Object> clearAll() {
        logService.deleteAll();
        return ApiResult.SUCCESS.getMap();
    }

}

